﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketService.Company;
using BCGPSCommon;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Page.Company
{
    /// <summary>
    /// 公司
    /// </summary>
    [ApiExplorerSettings(GroupName = "SystemAccount")]
    [Route("api/[controller]")]
    [ApiController]
    public class CompanyController : PageBaseController
    {
        private readonly ICompanyService companyService;

        #region 构造
        /// <summary>
        /// 
        /// </summary>
        /// <param name="companyService"></param>
        public CompanyController(ICompanyService companyService)
        {
            this.companyService = companyService;
        }
        #endregion

        #region 添加公司
        /// <summary>
        /// 添加公司
        /// </summary>
        /// <param name="companyRequestDto"></param>
        /// <returns></returns>
        [HttpPost("[action]")]
        [ProducesResponseType(typeof(CompanyDto), 200)]
        public CompanyDto Add(CompanyRequestDto companyRequestDto)
        {
            return companyService.AddNew(companyRequestDto);
        }
        #endregion

        #region 修改公司信息
        /// <summary>
        /// 修改公司信息
        /// </summary>
        /// <param name="companyDto"></param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(CompanyDto), 200)]
        public CompanyDto Update(CompanyDto companyDto)
        {
            return companyService.Update(companyDto);
        }
        #endregion

        /// <summary>
        /// 查询公司列表 -- 分页
        /// </summary>
        /// <param name="companyName">公司名称</param>
        /// <param name="desc">是否倒序</param>
        /// <param name="index">页码</param>
        /// <param name="size">记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<CompanyDto>), 200)]
        public PageableList<CompanyDto>  QueryPage([FromQuery(Name = "company_name")]string companyName, bool? desc=false, int? index=0 , int? size =20)
        {
            return companyService.GetList(companyName, desc.Value, index.Value, size.Value);
        }

        /// <summary>
        /// 删除公司
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <returns></returns>
        [HttpDelete("[action]/{company_id}")]
        [ProducesResponseType(typeof(bool),200)]
        public bool Delete([FromRoute (Name ="company_id")]int companyId)
        {
            return companyService.Delete(companyId);
        }
    }
}